package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.MapDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.CheckItem;
import com.itheima.pojo.Map;
import com.itheima.service.MapService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass = MapService.class)
@Transactional
public class MapServiceImpl implements MapService {
    @Autowired
    private MapDao mapDao;

    //查询地址
    @Override
    public List<Map> findAllAddress() {
        List<Map> list = mapDao.findAllAddress();
        return list;
    }

    //分页查询
    public PageResult pageQuery(QueryPageBean queryPageBean) {
        Integer currentPage = queryPageBean.getCurrentPage();  //分页查询的当前记录数
        Integer pageSize = queryPageBean.getPageSize();         //每页记录数
        String queryString = queryPageBean.getQueryString();    //查询条件
        PageHelper.startPage(currentPage,pageSize);// ? ?
        Page<Map> page = mapDao.findByCondition(queryString);

        return new PageResult(page.getTotal(),page.getResult());
    }

    //根据ID删除
    public void deleteById(Integer id) {
        //判断当前检查项是否已经关联到检查组
        mapDao.deleteById(id);
    }

    public void add(Map map) {
        mapDao.add(map);
    }

    public List<Map> findAll() {
        return mapDao.findAll();
    }









}
